<?php
class GoodsControl extends CommonControl {
	public function index(){
		$goods=new GoodsModel();
		$goodsData=$goods->selGoods();
		require_once('View/Admin/Goods/goodslist.php');
	}
	public function add(){
		$brand=new BrandModel();
		$brandData=$brand->fetchAll();
		$cate=new CategoryModel();
		$cateData=$cate->fetchAll();
		$cateData=pidsort($cateData);
		require('View/Admin/Goods/add.php');
	}
	public function addck(){
		require(TOOlS_DIR.'/Upload.class.php');
		$photo=new Upload('photo');
		$_POST['photo']=$photo->up(PUBLIC_DIR.'/Admin/upload');
		$_POST['ctime']=time();
		$goods=new GoodsModel();
		
		$num=$goods->insertID($_POST);
		
		//goodCate表数据
		$cate=new CategoryModel();
		$goodsCate=new GoodsCateModel();
		$goodsID=$goods->insertID;
		$cateID=$_POST['cid'];
		$catePID=$cate->selpid($cateID);
		$goodsCateData=array(
			'goodsID'=>$goodsID,
			'cateID'=>$cateID,
			'catePID'=>$catePID
		);
		$GCnum=$goodsCate->insert($goodsCateData);
		if(!$GCnum){
			die(mysql_error());
		}
		
		if($num==1){
			$this->success('/index.php/Admin/Goods/add');
		}else{
			$this->error('/index.php/Admin/Goods/add');
		}
	}
	public function update(){
		$id=$_GET['id'];
		$brand=new BrandModel();
		$brandData=$brand->fetchAll();
		$cate=new CategoryModel();
		$cateData=$cate->fetchAll();
		$goods=new GoodsModel();
		$goodsData=$goods->fetchRow($id);
		require('View/Admin/Goods/update.php');
	}
	public function updateck(){
		$goods=new GoodsModel();
		$num=$goods->update($_POST);
		if($num==1){
			$this->success('/index.php/Admin/Goods/index');
		}else{
			$this->error('/index.php/Admin/Goods/update');
		}
	}
	public function delete(){
		$id=$_GET['id'];
		$goods=new GoodsModel();
		$num=$goods->delete($id);
		if($num==1){
			$this->success('/index.php/Admin/Goods/index');
		}else{
			$this->error('/index.php/Admin/Goods/index');
		}
	}
}
?>